<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>promise</title>
</head>

<body>
  <script>
    // const p1 = new Promise((resolve, reject) => {
    //   var xhttp = new XMLHttpRequest();
    //   xhttp.onreadystatechange = function () {
    //     if (this.readyState == 4 && this.status == 200) {
    //       resolve(this.responseText)

    //     } else {
    //       reject(this.responseText)
    //     }
    //   };
    //   xhttp.open('GET', url, true);
    //   xhttp.send();
    // })

    function getData(url) {
      return new Promise((resolve, reject) => {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
          if (this.readyState == 4 && this.status == 200) {
            resolve(this.responseText)

          }
        };
        xhttp.open('GET', url, true);
        xhttp.send();
      })
    }
    getData('https://www.fastmock.site/mock/398fac2ec0ca141f96bf0b183fe4d621/mywebsite/blotlist')
      .then((res1) => {
        console.log('成功', res1);
        return getData('https://www.fastmock.site/mock/398fac2ec0ca141f96bf0b183fe4d621/mywebsite/blotlist')
      })
      .then(res2 => {
        console.log(res2)
        return getData('https://www.fastmock.site/mock/398fac2ec0ca141f96bf0b183fe4d621/mywebsite/blotlist')
      })
      .then(res3 => { console.log(res3); })


    // const p2 = new Promise((resolve, reject) => {
    //   if (true) {
    //     resolve('成功')
    //   } else {
    //     reject('失败')
    //   }
    // })
    // p2.then((res) => {
    //   console.log(res);
    // }).catch(err => console.log(err))
  </script>
</body>

</html>